package com.purong.purong.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.purong.purong.R;
import com.purong.purong.bean.AreaBean;
import com.purong.purong.util.CommonUtil;

import java.util.ArrayList;
import java.util.List;

/**
 * 城市选择-热门城市
 */
public class HotCityAdapter extends RecyclerView.Adapter<HotCityAdapter.ViewHolder> {


    private List<AreaBean> areaList = new ArrayList<>();
    private OnAreaClickListener mListener;
    private Context mContext;
    private int width,height;
    private LinearLayout.LayoutParams lp;
    public HotCityAdapter(Context context, int width, int height) {
        this.mContext = context;
        this.width=width;
        this.height=height;
        lp=new LinearLayout.LayoutParams(width,height);
        lp.setMargins(0,0,0, CommonUtil.dip2px(mContext,15));
    }
    public void setOnAreaClickListener(OnAreaClickListener listener){
        this.mListener=listener;
    }
    public void setData(List<AreaBean> jokeList) {
//        if (Utils.isEmpty(imageList)) {
//            return;
//        }
        this.areaList = jokeList;
    }


    /**
     * 通过ViewHolder可以访问每个item的所有控件
     */
    public static class ViewHolder extends RecyclerView.ViewHolder {
        //绑定每个CircleItem的控件引用到ViewHolder

        private TextView hotCity;
        public LinearLayout itemLay;
        public ViewHolder(View v) {
            super(v);
            hotCity = (TextView) v
                    .findViewById(R.id.hot_city);

        }
    }


    // 创建每个Item的视图 (invoked by the item_circle manager)
    @Override
    public HotCityAdapter.ViewHolder onCreateViewHolder(ViewGroup parent,
                                                        int viewType) {
        //创建circleItem所对应的控件
        View v = LayoutInflater.from(parent.getContext())
                .inflate(R.layout.hot_city_item, parent, false);
        // set the view's size, margins, paddings and item_circle parameters
        ViewHolder vh = new ViewHolder(v);

        return vh;
    }

    // Replace the contents of a view (invoked by the item_circle manager)
    @Override
    public void onBindViewHolder(final ViewHolder mHolder, final int position) {
        Log.e("zwj",".....zwj");
        mHolder.hotCity.setLayoutParams(lp);
        mHolder.hotCity.setText(areaList.get(position).getAcronym());
        mHolder.hotCity.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (mListener!=null){
                    mListener.onClick(areaList.get(position));
                }
            }
        });
    }



    // 获取Circle数据的item个数
    @Override
    public int getItemCount() {
        return areaList.size();
    }

    public interface OnAreaClickListener{
        void onClick(AreaBean area);
    }
}


